package com.telchina.common.controller;

import com.telchina.common.annotation.Log;
import com.telchina.common.core.controller.BaseController;
import com.telchina.common.core.domain.AjaxResult;
import com.telchina.common.enums.BusinessType;
import com.telchina.common.utils.poi.ExcelUtil;
import com.telchina.common.domain.WoCategary;
import com.telchina.common.service.IWoCategaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类字典Controller
 *
 * @author konghao
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/common/categary")
public class WoCategaryController extends BaseController {
    @Autowired
    private IWoCategaryService woCategaryService;

    /**
     * 分页查询分类字典列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:list')")
    @GetMapping("/list")
    public AjaxResult list(WoCategary woCategary) {
//        IPage<WoCategary> list = woCategaryService.selectList(startPage(), woCategary);
        List<WoCategary> list = woCategaryService.selectListAll(woCategary);
        return AjaxResult.success(list);
    }

    /**
     * 查询分类字典列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(WoCategary woCategary) {
        List<WoCategary> list = woCategaryService.selectListAll(woCategary);
        return AjaxResult.success(list);
    }

    /**
     * 导出分类字典列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:export')")
    @Log(title = "分类字典" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WoCategary woCategary) {
        List<WoCategary> list = woCategaryService.selectListAll(woCategary);
        ExcelUtil<WoCategary> util = new ExcelUtil<WoCategary>(WoCategary.class);
        return util.exportExcel(list, "categary");
    }

    /**
     * 获取分类字典详细信息
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(woCategaryService.selectById(id));
    }

    /**
     * 新增分类字典
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:add')")
    @Log(title = "分类字典" , businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody WoCategary woCategary) {
        return toAjax(woCategaryService.insert(woCategary));
    }

    /**
     * 修改分类字典
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:edit')")
    @Log(title = "分类字典" , businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    public AjaxResult edit(@RequestBody WoCategary woCategary) {
        return toAjax(woCategaryService.update(woCategary));
    }

    /**
     * 删除分类字典
     */
    // @PreAuthorize("@ss.hasPermi('workorder:categary:remove')")
    @Log(title = "分类字典" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return woCategaryService.deleteByIds(ids);
    }
}
